home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / vbasic / prof_vb.zip / PROFIL.BAS < prev   
BASIC Source File  |  1994-01-20  |  4KB  |  106 lines

  1. ' User Profile Routines
  2. ' NOTE: The lpKeyName argument for GetProfileString, WriteProfileString,
  3. '       GetPrivateProfileString, and WritePrivateProfileString can be either
  4. '       a string or NULL.  This is why the argument is defined as "By Any".
  5. '          For example, to pass a string specify   ByVal "wallpaper"
  6. '          To pass NULL specify                    ByVal 0&
  7. '       You can also pass NULL for the lpString argument for WriteProfileString
  8. '       and WritePrivateProfileString
  9.  
  10. Declare Function GetPrivateProfileInt Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Integer, ByVal lpFileName As String) As Integer
  11. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  12. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, lpKeyName As Any, lpString As Any, ByVal lplFileName As String) As Integer
  13. Declare Function GetWindowsDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  14. Declare Function GetSystemDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  15.  
  16. Function GetINIInt (FileName As String, Application As String, Parameter As String) As Integer
  17.         
  18.         If InStr(1, FileName, "\") = 0 Then
  19.         If FileName = "" Then
  20.                 FileName = WinDir() + "WIN.INI"
  21.         Else
  22.                 FileName = WinDir() + FileName
  23.         End If
  24.     End If
  25.     GetINIInt = GetPrivateProfileInt(Application, Parameter, 0, FileName)    ' Make API Call
  26. End Function
  27.  
  28. Function GetINIString (FileName As String, Application As String, Parameter As String) As String
  29.     temp$ = String$(255, 0)                 ' Size Buffer
  30.     If InStr(1, FileName, "\") = 0 Then
  31.         If FileName = "" Then
  32.                 FileName = WinDir() + "WIN.INI"
  33.         Else
  34.                 FileName = WinDir() + FileName
  35.         End If
  36.     End If
  37.     x = GetPrivateProfileString(Application$, ByVal Parameter$, "", temp$, 255, FileName$)   ' Make API Call
  38.     temp$ = Left$(temp$, x)                 ' Trim Buffer
  39.     GetINIString$ = temp$
  40. End Function
  41.  
  42. Function GetProgExt () As String
  43.     Value$ = GetINIString("WIN.INI", "Windows", "Programs")
  44.     Res% = 0
  45.     Do While True
  46.         Res1% = InStr(Res% + 1, Value$, " ")
  47.         If Res1% = 0 And Len(Value$) = 0 Then
  48.             Exit Do
  49.         Else
  50.             If Res1% > 0 Then
  51.                 tVal$ = Mid(Value$, Res% + 1, Res1% - (Res% + 1))
  52.             Else
  53.                 tVal$ = Mid(Value$, Res% + 1, Len(Value$) - (Res%))
  54.                 Value$ = ""
  55.             End If
  56.             If Len(ProgTemp$) > 0 Then
  57.                 ProgTemp$ = ProgTemp$ + ";"
  58.             End If
  59.             ProgTemp$ = ProgTemp$ + "*." + tVal$
  60.         End If
  61.         Res% = Res1%
  62.         Loop
  63.     GetProgExt$ = ProgTemp$
  64.     
  65. End Function
  66.  
  67. Function SysDir () As String
  68.     temp$ = String$(145, 0)                 ' Size Buffer
  69.     x = GetSystemDirectory(temp$, 145)      ' Make API Call
  70.     temp$ = Left$(temp$, x)                 ' Trim Buffer
  71.  
  72.     If Right$(temp$, 1) <> "\" Then         ' Add \ if necessary
  73.         SysDir$ = temp$ + "\"
  74.     Else
  75.         SysDir$ = temp$
  76.     End If
  77. End Function
  78.  
  79. Function WinDir () As String
  80.     temp$ = String$(145, 0)              ' Size Buffer
  81.     x = GetWindowsDirectory(temp$, 145)  ' Make API Call
  82.     temp$ = Left$(temp$, x)              ' Trim Buffer
  83.  
  84.     If Right$(temp$, 1) <> "\" Then      ' Add \ if necessary
  85.         WinDir$ = temp$ + "\"
  86.     Else
  87.         WinDir$ = temp$
  88.     End If
  89. End Function
  90.  
  91. Function WriteINI (FileName As String, Application As String, Parameter As String, Value As String) As Integer
  92.     If InStr(1, FileName, "\") = 0 Then
  93.         If FileName = "" Then
  94.             FileName = WinDir() + "WIN.INI"
  95.         Else
  96.             FileName = WinDir() + FileName
  97.         End If
  98.     End If
  99.     If Value = "" Then
  100.         WriteINI = WritePrivateProfileString(Application$, ByVal Parameter$, ByVal 0&, FileName$)
  101.     Else
  102.         WriteINI = WritePrivateProfileString(Application$, ByVal Parameter$, ByVal Value$, FileName$)
  103.     End If
  104. End Function
  105.  
  106.